from datetime import datetime
from decimal import Decimal
from typing import Optional

from pydantic import BaseModel, ConfigDict, Field
from pydantic.alias_generators import to_camel

from module_admin.annotation.pydantic_annotation import as_query


class StatStockModel(BaseModel):
    """
    股票统计表对应pydantic模型
    """
    model_config = ConfigDict(alias_generator=to_camel, from_attributes=True)

    stock_code: Optional[str] = Field(default=None, description='证券代码')
    stock_name: Optional[str] = Field(default=None, description='证券名称')
    account_tag: Optional[str] = Field(default=None, description='股票账号标签')
    total_buy_amount: Optional[Decimal] = Field(default=None, description='累计买入金额')
    total_buy_quantity: Optional[int] = Field(default=None, description='累计买入数量')
    total_sell_amount: Optional[Decimal] = Field(default=None, description='累计卖出金额')
    total_sell_quantity: Optional[int] = Field(default=None, description='累计卖出数量')
    profit: Optional[Decimal] = Field(default=None, description='盈利')
    create_time: Optional[datetime] = Field(default=None, description='创建时间')


@as_query
class StatStockPageQueryModel(StatStockModel):
    """
    股票统计分页查询模型
    """

    page_num: int = Field(default=1, description='当前页码')
    page_size: int = Field(default=10, description='每页记录数')
    zero: Optional[bool] = Field(default=None, description='是否只显示清仓股票')


class DeleteStatStockModel(BaseModel):
    """
    删除股票统计模型
    """

    model_config = ConfigDict(alias_generator=to_camel)

    stock_codes: str = Field(description='需要删除的证券代码')
